const restorative = require('../service/restorative')

// 获取药品列表
const getRestorativeList = async(ctx)=>{
    let res = await restorative.getRestorativeList(ctx.query)
    if(res.length > 0){
        return ctx.body = {
            code: 200,
            data: res,
            total:res.length,
            message: '获取成功'
        }
    }
}

// 获取药品分类
const getRestorativeType = async(ctx)=>{
    let res = await restorative.getRestorativeType(ctx.query)
    if(res.length > 0){
        return ctx.body = {
            code: 200,
            data: res,
            message: '获取成功'
        }
    }
}

// 获取药品详情
const getRestorativeDetail = async(ctx)=>{
    let res = await restorative.getRestorativeDetail(ctx.query)
    if(res.length > 0){
        return ctx.body = {
            code: 200,
            data: res,
            message: '获取成功'
        }
    }
}

// 删除药品
const deleteRestorative = async(ctx)=>{
    let res = await restorative.deleteRestorative(ctx.query)
    if(res.affectedRows){
        return ctx.body = {
            code: 20000,
            message: '删除成功'
        }
    }else{
        return ctx.body = {
            code:40001,
            msg:'删除失败'
        }
    }
}

// 新增药品
const addRestorative = async(ctx)=>{
    let res = await restorative.restorativeAdd(ctx.request.body)
    if(res.affectedRows){
        return ctx.body = {
            code: 20000,
            message: '添加成功'
        }
    }else{
        return ctx.body = {
            code:40001,
            msg:'添加失败'
        }
    }
}

// 编辑药品
const editRestorative = async(ctx)=>{
    let res = await restorative.restorativeEdit(ctx.request.body)
    if(res.affectedRows){
        return ctx.body = {
            code: 20000,
            message: '编辑成功'
        }
    }else{
        return ctx.body = {
            code:40001,
            msg:'编辑失败'
        }
    }
}

module.exports = {
    getRestorativeList,
    getRestorativeDetail,
    getRestorativeType,
    deleteRestorative,
    addRestorative,
    editRestorative
}